﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EuroManager.Domain.Simulator.AI;
using EuroManager.Domain.Simulator.Engine;
using EuroManager.Domain.Simulator.Tests.World;
using EuroManager.Domain.Simulator.World;
using NUnit.Framework;
using Rhino.Mocks;

namespace EuroManager.Domain.Simulator.Tests.AI
{
    [TestFixture]
    public class TeamAITests
    {
        [Test]
        public void ShouldOrderPlayerWithBestChancesToChaseBall()
        {
            IPlayer player1 = MockRepository.GenerateStub<IPlayer>();
            IPlayer player2 = MockRepository.GenerateMock<IPlayer>();
            ITeam team = MockRepository.GenerateStub<ITeam>();
            
            player1.Stub(p => p.TimeToReachBall).Return(0.3f);
            player2.Stub(p => p.TimeToReachBall).Return(0.2f);
            team.Stub(t => t.Players).Return(TestHelper.Enumerable(player1, player2));

            player2.Expect(p => p.ChaseBall());

            TeamAI teamAI = new TeamAI(team, new FakeRandomizer());
            TestHelper.Advance(1, teamAI);

            player2.VerifyAllExpectations();
        }

        [Test]
        public void ShouldOrderPlayerWithLowerChancesToObserve()
        {
            IPlayer player1 = MockRepository.GenerateMock<IPlayer>();
            IPlayer player2 = MockRepository.GenerateStub<IPlayer>();
            ITeam team = MockRepository.GenerateStub<ITeam>();

            player1.Stub(p => p.TimeToReachBall).Return(0.3f);
            player2.Stub(p => p.TimeToReachBall).Return(0.2f);
            team.Stub(t => t.Players).Return(TestHelper.Enumerable(player1, player2));

            player1.Expect(p => p.Observe());

            TeamAI teamAI = new TeamAI(team, new FakeRandomizer());
            TestHelper.Advance(1, teamAI);

            player1.VerifyAllExpectations();
        }
    }
}
